export var teachers = {
    'T08076': {
      id: 'T08076',
      name: '张胜男',
      college: '物理与信息学院',
      title: '教授',
      password: '123456',
      admin: '0'
    },
    'T05962': {
      id: 'T05962',
      name: '李贤',
      college: '计算机与大数据学院',
      title: '副教授',
      password: '123456',
      admin: '1'
    },
    'T025687': {
      id: 'T025687',
      name: '张怀民',
      college: '物理与信息学院',
      title: '讲师',
      password: '123456',
      admin: '0'
    }
}
export var students = {
    '221701336': {
        s_id: '221701336',
        name: '小白',
        major: '电子信息',
        grade: '2021级',
        college: 'XXX学院',
        password: '123456'
    },
    '211035645': {
      s_id: '211035645',
      name: '小河',
      major: '电子信息',
      grade: '2021级',
      college: 'XXX学院',
      password: '123456'
    },
    '211035685': {
      s_id: '211035685',
      name: '下黑',
      major: '电子信息',
      grade: '2021级',
      college: 'XXX学院',
      password: '123456'
    },
    '2110323215': {
      s_id: '2110323215',
      name: '下黑',
      major: '电子信息',
      grade: '2021级',
      college: 'XXX学院',
      password: '123456'
    },
    '2134354385': {
      s_id: '2134354385',
      name: '下黑',
      major: '电子信息',
      grade: '2021级',
      college: 'XXX学院',
      password: '123456'
    },
    '21103534325': {
      s_id: '21103534325',
      name: '下黑',
      major: '电子信息',
      grade: '2021级',
      college: 'XXX学院',
      password: '123456'
    }
}
var classes = {
    '0001': { 
            id: '0001',
            name: 'java编程课',
            introduction: '这是一门教Java编程的课程'
        },
    '0002': {
            id: '0002',
            name: 'python编程课',
            introduction: '这是一门教python编程的课程'
        },
    '0003': {
              id: '0003',
              name: 'c语言编程课',
              introduction: '这是一门教c语言编程的课程'
          },
    '0004': {
              id: '0004',
              name: 'web编程课',
              introduction: '这是一门教web编程的课程'
          }
}
var tests = {
    '0001': [
        {
            test_id : 'p4526836',
            start_time: '2021-01-03 10:00:00',
            end_time: '2022-02-20 12:00:00',
            exam_time: '120',
            exam_name: '期中考',
            publish: '0'
        },
        {
            test_id : 'p4526844',
            start_time: '2021-01-03 10:00:00',
            end_time: '2022-02-20 12:00:00',
            exam_time: '120',
            exam_name: '期中考',
            publish: '1'
        }
    ],
    '0002': [
        {
            test_id : 'p45265665',
            start_time: '2021-01-03 10:00:00',
            end_time: '2022-02-23 12:00:00',
            exam_time: '120',
            exam_name: '期中考',
            publish: '1'
        },
        {
            test_id : 'p4526845',
            start_time: '2021-01-03 10:00:00',
            end_time: '2022-02-20 12:00:00',
            exam_time: '120',
            exam_name: '期中考',
            publish: '0'
        }
    ],
    '0003': [
        {
            test_id : 'p45268236',
            start_time: '2021-01-03 10:00:00',
            end_time: '2021-01-03 12:00:00',
            exam_time: '120',
            exam_name: '期中考',
            publish: '1'
        }
    ]
}
var papers = {
    'p45268236': {
        one_select: [
            {
                number: '1',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'A'
            },
            {
                number: '2',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'B'
            }
        ],
        multi_select: [
            {
                number: '3',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'AC'
            },
            {
                number: '4',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'ABC'
            }
        ],
        fill_blank: [
            {
                number: '5',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            },
            {
                number: '6',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            }
        ],
        judgement: [
            {
                number: '7',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '0'
            },
            {
                number: '8',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '1'
            }
        ]
    },
    'p4526844': {
        one_select: [
            {
                number: '1',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'A'
            },
            {
                number: '2',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'B'
            }
        ],
        multi_select: [
            {
                number: '3',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'AC'
            },
            {
                number: '4',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'ABC'
            }
        ],
        fill_blank: [
            {
                number: '5',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            },
            {
                number: '6',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            }
        ],
        judgement: [
            {
                number: '7',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '0'
            },
            {
                number: '8',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '1'
            }
        ]
    },
    'p45265665': {
        one_select: [
            {
                number: '1',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'A'
            },
            {
                number: '2',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'B'
            }
        ],
        multi_select: [
            {
                number: '3',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'AC'
            },
            {
                number: '4',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'ABC'
            }
        ],
        fill_blank: [
            {
                number: '5',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            },
            {
                number: '6',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            }
        ],
        judgement: [
            {
                number: '7',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '0'
            },
            {
                number: '8',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '1'
            }
        ]
    },
    'p4526845': {
        one_select: [
            {
                number: '1',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'A'
            },
            {
                number: '2',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'B'
            }
        ],
        multi_select: [
            {
                number: '3',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'AC'
            },
            {
                number: '4',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'ABC'
            }
        ],
        fill_blank: [
            {
                number: '5',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            },
            {
                number: '6',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            }
        ],
        judgement: [
            {
                number: '7',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '0'
            },
            {
                number: '8',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '1'
            }
        ]
    },
    'p4526836': {
        one_select: [
            {
                number: '1',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'A'
            },
            {
                number: '2',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'B'
            }
        ],
        multi_select: [
            {
                number: '3',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'AC'
            },
            {
                number: '4',
                title: 'XXXXXXXXXX',
                opt1: 'XXX',
                opt2: 'XXX',
                opt3: 'XXX',
                opt4: 'XXX',
                score: '5',
                answer: 'ABC'
            }
        ],
        fill_blank: [
            {
                number: '5',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            },
            {
                number: '6',
                title: 'XXXXXXXXXX___XXX',
                score: '5',
                answer: '填空'
            }
        ],
        judgement: [
            {
                number: '7',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '0'
            },
            {
                number: '8',
                title: 'XXXXXXXXXXXXX',
                score: '5',
                answer: '1'
            }
        ]
    }
}
var scores = {
    'p4526836': {
    },
    'p45268236': {
        '221701336': 40
    },
    'p4526844': {
        '221701336': 40
    },
    'p45265665': {
        '221701336': 40
    },
    'p4526845': {
        '221701336': 40
    }

}
var teacher_classes = {
    'T08076': ['0001', '0002'],
    'T05962': ['0003', '0004']
}
var student_classes = {
    '221701336': ['0001', '0004']
}

export default [
    // 学生获取课表
    {
      url: '/student/classesList',
      type: 'post',
      response: config => {
        const { s_id } = config.body
        console.log(s_id)
        console.log(student_classes)
        const classID= student_classes[s_id]
        if (!classID) {
          return {
            code: 401,
            message: '你当前还没有加入任何课程'
          }
        }
        var _classes = []
        for (var item in classID) {
            _classes.push(classes[classID[item]])
        }
        const result = {
          'classes': _classes
        }

        return result
      }
    },
    //学生获取考试列表
    {
        url: '/studet/paper/list',
        type: 'post',
        response: config => {
            const { s_id, c_id } = config.body
            console.log(c_id)
            const _tests = tests[c_id]
            console.log(_tests)
            if (!_tests) {
                return {
                    code: 401,
                    message: '暂无考试'
                }
            }
            var exams = []
            for (var item in _tests) {
                var test = {
                    end_time: _tests[item].end_time,
                    exam_name: _tests[item].exam_name,
                    exam_time: _tests[item].exam_time,
                    start_time: _tests[item].start_time,
                    test_id: _tests[item].test_id,
                    // reply: '',
                    start: '0'
                }
                var startTime = new Date(test.start_time)
                var endTime = new Date(test.end_time)
                var currentTime = new Date()
                if (startTime <= currentTime && currentTime <= endTime && papers[_tests[item].test_id]) {
                    test.start = '1'
                }
                var testID = _tests[item].test_id
                if (scores[testID] == undefined){
                    scores[testID] = {}
                }
                var _scores = scores[testID]
                console.log(item)   
                if (_scores[s_id] == undefined) {
                    test.reply = '0'
                } else {
                    test.reply ='1'
                }
                if(_tests[item].publish == '1') {
                    exams.push(test)
                }
            }
            return {
                exams: exams
            }
        }
    },
     // 学生获取考试成绩
    {
        url: '/studet/paper/score',
        type: 'post',
        response: config => {
            const { test_id, s_id } = config.body
            var test = {}
            for(var item in tests) {
                for(var item2 in tests[item]) {
                    if (tests[item][item2].test_id == test_id) {
                        test = tests[item][item2]
                    }
                }
            }
            var totalScore = 0
            for(var item in papers[test_id]) {
                for(var item2 in papers[test_id][item]) {
                    totalScore += parseInt(papers[test_id][item][item2].score)
                }
            }
            return {
                exam_name: test.exam_name,
                score: scores[test_id][s_id],
                totalScore
            }

        }
    },
    //学生获取试卷
    {
        url: '/studet/paper/get',
        type: 'post',
        response: config => {
            const { test_id } = config.body
            var tests = papers[test_id]
            return {
                test_id: test_id,
                tests
            }
        }
    },
    //学生提交答案
    {
        url: '/studet/paper/submit',
        type: 'post',
        response: config => {
            const { test_id, s_id, answers } = config.body
            console.log(test_id)
            console.log(s_id)
            console.log(answers)
            var score = 0
            const paper = papers[test_id]
            for (var item in answers) {
                for (var item2 in paper) {
                    for (var item3 in paper[item2]){
                        if (paper[item2][item3].number == answers[item].number && paper[item2][item3].answer == answers[item].answer) {
                            score += parseInt(paper[item2][item3].score)
                        }
                    }
                }
            }
            scores[test_id][s_id] = score
            return {
                code: 200
            }
        }
    },
    //教师获取任课列表
    {
        url: '/teacher/classesList',
        type: 'post',
        response: config => {
          const { tid } = config.body
          const classID= teacher_classes[tid]
  
          // mock error
          if (!classID) {
            return {
              code: 401,
              message: '还没有任课.'
            }
          }
          var _classes = []
          for (var item in classID) {
              _classes.push(classes[classID[item]])
          }
          const result = {
            'classes': _classes
          }
          return result
        }
    },
    //教师获取课程学生信息
    {
        url: '/teacher/class/student/list',
        type: 'post',
        response: config => {
          const { c_id } = config.body
          var _students =  []
          for (var item in student_classes) {
              if (student_classes[item].includes(c_id)) {
                  _students.push(students[item])
              }
          }
          return {
            students: _students
          }
        }
    },
    //教师获取考试安排
    {
        url: '/teacher/exam/list',
        type: 'post',
        response: config => {
            const { c_id } = config.body
            var _tests = tests[c_id]
            for (var item in _tests) {
                if (papers[_tests[item].test_id]) {
                    _tests[item].has_paper = '1'
                } else {
                    _tests[item].has_paper = '0'
                }
                var endTime = new Date(_tests[item].end_time)
                var currentTime = new Date()
                if(endTime < currentTime) {
                    _tests[item].finish = '1'
                } else {
                    _tests[item].finish = '0'
                }
                var totalScore = 0
                for(var item2 in papers[_tests[item].test_id]) {
                    for(var item3 in papers[_tests[item].test_id][item2]) {
                        totalScore += parseInt(papers[_tests[item].test_id][item2][item3].score)
                    }
                }
                _tests[item].score = totalScore
            }
            return {
                exams: _tests
            }
        }
    },
    //教师添加考试安排
    {
        url: '/teacher/exam/add',
        type: 'post',
        response: config => {
            const { c_id, exam_name, exam_time, start_time, end_time, type } = config.body
            var randNUmber = Math.ceil(Math.random()*10000000);
            var newID = 'p'+randNUmber
            var new_test = {
                test_id: newID,
                start_time: start_time,
                end_time: end_time,
                exam_time: exam_time,
                exam_name: exam_name,
                publish: type
            }
            if(!tests[c_id]) {
                tests[c_id] = []
            }
            tests[c_id].push(new_test)
        }
    },
    //教师添加试卷
    {
        url: '/teacher/paper/add',
        type: 'post',
        response: config => {
            const { test_id, paper } = config.body
            papers[test_id] = paper
            console.log( papers[test_id] )
            return {
                code: 200
            }
        }
    },
    //教师修改课程信息
    {
        url: '/teacher/class/update',
        type: 'post',
        response: config => {
            const { c_id, new_name, new_introduction } = config.body
            classes[c_id].name = new_name
            classes[c_id].introduction = new_introduction
            return {
                code: 200
            }
        }
    },
    //教师创建课程
    {
        url: '/teacher/class/create',
        type: 'post',
        response: config => {
          const { t_id, c_name, c_introduction } = config.body
          var randNUmber = Math.ceil(Math.random()*100000);
          var new_class = {
            id: randNUmber.toString(),
            name: c_name,
            introduction: c_introduction
          }
          if(teacher_classes[t_id] == undefined) {
            teacher_classes[t_id]=[] 
          }
          teacher_classes[t_id].push(randNUmber)
          classes[randNUmber]=new_class
          console.log(classes)
          return {
            code: 200
          }
        }
    },
    //教师添加课程学生
    {
        url: '/teacher/class/student/add',
        type: 'post',
        response: config => {
            const { c_id, s_ids } = config.body
            for (var item in s_ids) {
                if (student_classes[s_ids[item].number] == undefined){
                    student_classes[s_ids[item].number] = []
                }
                if (!student_classes[s_ids[item].number].includes(c_id)) {
                    student_classes[s_ids[item].number].push(c_id)
                }
            }
            console.log(student_classes)
            console.log(classes)
        }
    },
    //教师发布试卷
    {
        url: '/teacher/paper/publis',
        type:'post',
        response: config => {
            const { test_id, c_id } = config.body
            for (var item in tests[c_id]) {
                if(tests[c_id][item].test_id == test_id) {
                    tests[c_id][item].publish = '1'
                }
            }
            return {
                code: 200
            }
        }
    },
    //教师发布试卷
    {
        url: '/teacher/paper/unpublis',
        type:'post',
        response: config => {
            const { test_id, c_id } = config.body
            for (var item in tests[c_id]) {
                if(tests[c_id][item].test_id == test_id) {
                    tests[c_id][item].publish = '0'
                }
            }
            return {
                code: 200
            }
        }
    },
    //教师查看试卷
    {
        url: '/teacher/paper/get',
        type:'post',
        response: config => {
            const { test_id } = config.body
            return {
                paper: papers[test_id]
            }
        }
    },
    //教师删除试卷
    {
        url: '/teacher/paper/delet',
        type:'post',
        response: config => {
            const { test_id } = config.body
            for (var item in tests) {
                for (var item2 in tests[item]) {
                    if (tests[item][item2].test_id == test_id) {
                        tests[item].splice(item2, 1);
                    }
                }
            }
            return {
                code: 200
            }
        }
    },
    //教师获取试卷成绩
    {
        url: '/teacher/paper/score',
        type:'post',
        response: config => {
            const { test_id, c_id } = config.body
            const _scores = scores[test_id]
            var _students =  []
            for (var item in student_classes) {
                if (student_classes[item].includes(c_id)) {
                    _students.push(students[item])
                }
            }
            var returnData=[]
            for (var item in _students) {
                var newItem = {
                    studentName: _students[item].name,
                }
                if(_scores[_students[item].s_id]) {
                    newItem.score = _scores[_students[item].s_id]
                } else {
                    newItem.score = '--'
                }
                returnData.push(newItem)
            }
            console.log(_scores)
            console.log(_students)
            return {
                code: 200,
                score: returnData
            }
        }
    },
    //管理员获取学生列表
    {
        url: '/admin/studentList',
        type: 'post',
        response: config => {
            var _students = []
            for (var item in students) {
                _students.push(students[item])
            }
            return {
                students: _students
            }
        }
    },
    //管理员添加学生
    {
        url: '/admin/student/create',
        type: 'post',
        response: config => {
            const {s_college,s_id, password, s_name, s_major,s_grade} = config.body
            var new_students = {
                s_id: s_id,
                name: s_name,
                major: s_major,
                grade: s_grade,
                college: s_college,
                password: password
            }
            students[s_id]=new_students
            return {
                code: 200
            }
        }
    },
    //管理员修改学生信息
    {
        url: '/admin/student/change',
        type: 'post',
        response: config => {
            const {s_college,s_id, s_name, s_major, s_grade, password} = config.body
            var new_students = {
                s_id : s_id,
                name : s_name,
                major : s_major,
                grade : s_grade,
                college : s_college,
                password: password
            }
            students[s_id]=new_students
            return {
                code: 200
            }
        }
    },
    //管理员删除学生信息
    {
        url: '/admin/student/del',
        type: 'post',
        response: config => {
            const {s_id} = config.body
            delete students[s_id] 
            return {
                code: 200
            }
        }
    },
    //管理员获取教师列表
    {
        url: '/admin/teacher/list',
        type: 'post',
        response: config => {
            var _teachers = []
            for(var item in teachers) {
                _teachers.push(teachers[item])
            }
            return {
                teachers: _teachers
            }
        }
    },
    //管理员修改教师信息
    {
        url: '/admin/teacher/update',
        type: 'post',
        response:config => {
            const {t_id, new_name, new_password, new_college, new_title} = config.body
            teachers[t_id].name = new_name
            teachers[t_id].password = new_password
            teachers[t_id].college = new_college
            teachers[t_id].title = new_title
            return {
                code: 200
            }
        }
    },
    //管理员删除教师
    {
        url: '/admin/teacher/delet',
        type: 'post',
        response: config => {
            const { t_id } = config.body
            delete teachers[t_id]
            return {
                code: 200
            }
        }
    },
    //管理员添加教师
    {
        url: '/admin/teacher/add',
        type: 'post',
        response: config => {
            const { t_name, t_password, t_college, t_title } = config.body
            var newID = 'T' + Math.ceil(Math.random()*100000)
            var newTeacher = {
                id: newID,
                name: t_name,
                college: t_college,
                title: t_title,
                password: t_password
            }
            teachers[newID] = newTeacher
            return {
                code: 200
            }
        }
    }
]